/**
* */
Rsd.define('Rsd.Faith.pages.ReportZiJinZongZhangListPage', {
    extend: 'Rsd.Faith.pages.ListPage',
    requires: ['Rsd.controlEx.ComboBoxEnum','Rsd.Faith.controls.SuoShuQiInput'],
    xtype: 'list-r-zong_zhang',
    border: false,
    tabTitle: '总账户',
    searchColumns:[{name:'SuoShuQi',"text": "所属期",xtype:'ctrl-suoshuqi'}],
    newButtons:[{text:'重新核算',handler:'reportHs'}],
    modelType: 'ReportZiJinZongZhangModel',
    readOnly:true,
    formFields: [],
    gridColumns: [
            {
                "text": "序号",
                "xtype": "index",
                "width": 40,
                "index": 0,
                "deep": 1
            },
            {
                "name": "SuoShuQi",
                "dataIndex": "SuoShuQi",
                "sortable": false,
                "text": "所属期",
                align:'center',
                "index": 22,
                "exist": true,
                "xtype": "string",
                format:'suo_shu_qi_format',
                "width": 100,
                "nobr": true,
                "deep": 1
            },
        {
            "name": "ZhuangTai",
            "dataIndex": "ZhuangTai",
            "sortable": false,
            "text": "状态",
            format:'zhuang_tai_format',
            "index": 44,
            "exist": true,
            "width": 100,
            "nobr": true,
            "deep": 1,
            "xtype": "enum",
            "enum": {
                "name": "Rsd.Faith.Report.ZhuangMuZhuangTai",
                "items": [
                    {
                        "code": "None",
                        "text": "未设置",
                        "value": -1,
                        color:'grey'
                    },
                    {
                        "code": "JZZ",
                        "text": "记账中",
                        "value": 0
                    },
                    {
                        "code": "YHS",
                        "text": "已扎帐",
                        "value": 1
                    }
                ]
            }
        },
            {
                "name": "KaiShiRiQi",
                "dataIndex": "KaiShiRiQi",
                "sortable": false,
                "text": "开始日期",
                "index": 23,
                "exist": true,
                "xtype": "date",
                "formatString": "yyyy-MM-dd",
                "width": 100,
                "precision": 3,
                "deep": 1
            },
            {
                "name": "JieShuRiQi",
                "dataIndex": "JieShuRiQi",
                "sortable": false,
                "text": "结束日期",
                "index": 24,
                "exist": true,
                "xtype": "date",
                "formatString": "yyyy-MM-dd",
                "width": 100,
                "precision": 3,
                "deep": 1
            },
            {
                "name": "QiChuJinE_ZZ",
                "dataIndex": "QiChuJinE_ZZ",
                "sortable": false,
                "text": "期初(住房)",
                "index": 25,
                "exist": true,
                "xtype": "number",
                "width": 150,
                "precision": 2,
                "deep": 1
            },
            {
                "name": "JiaoCunJinE_ZZ",
                "dataIndex": "JiaoCunJinE_ZZ",
                "sortable": false,
                "text": "缴存(住宅)",
                "index": 28,
                "exist": true,
                "xtype": "number",
                "total":true,
                "width": 150,
                "precision": 2,
                "deep": 1
            },
            {
                "name": "ShiYongJinE_ZZ",
                "dataIndex": "ShiYongJinE_ZZ",
                "sortable": false,
                "text": "使用(住宅)",
                "total":true,
                "index": 32,
                "exist": true,
                "xtype": "number",
                "width": 150,
                "precision": 2,
                "deep": 1
            },
            {
                "name": "YuE_ZZ",
                "dataIndex": "YuE_ZZ",
                "sortable": false,
                "text": "余额(住宅)",
                "index": 40,
                "exist": true,
                "xtype": "number",
                "width": 150,
                "precision": 2,
                "deep": 1
            },
        {
            "name": "ShouYiJinE_ZZ",
            "dataIndex": "ShouYiJinE_ZZ",
            "sortable": false,
            "text": "分户利息合计",
            "index": 30,
            "exist": true,
            "xtype": "number",
            "total":true,
            "width": 100,
            "precision": 2,
            "deep": 1
        },
       /* {
                "name": "QiChuJinE_DT",
                "dataIndex": "QiChuJinE_DT",
                "sortable": false,
                "text": "期初(电梯/消防)",
                "index": 26,
                "exist": true,
                "xtype": "number",
                "width": 120,
                "precision": 2,
                "deep": 1
            },
            {
                "name": "JiaoCunJinE_DT",
                "dataIndex": "JiaoCunJinE_DT",
                "sortable": false,
                "text": "缴存(电梯/消防)",
                "index": 34,
                "exist": true,
                "xtype": "number",
                "width": 120,
                "precision": 2,
                "deep": 1
            },
            {
                "name": "ShiYongJinE_DT",
                "dataIndex": "ShiYongJinE_DT",
                "sortable": false,
                "text": "使用(电梯/消防)",
                "index": 38,
                "exist": true,
                "xtype": "number",
                "width": 120,
                "precision": 2,
                "deep": 1
            },
            {
                "name": "YuE_DT",
                "dataIndex": "YuE_DT",
                "sortable": false,
                "text": "余额(电梯/消防)",
                "index": 42,
                "exist": true,
                "xtype": "number",
                "width": 120,
                "precision": 2,
                "deep": 1
            },*/

            {
                "name": "Remark",
                "dataIndex": "Remark",
                "sortable": false,
                "text": "备注",
                "index": 50,
                "exist": true,
                "xtype": "string",
                "width": 50,
                "nobr": true,
                "deep": 1
            }
        ],
    sort:[{name:'SuoShuQi',direction:'asc'}],
    formTitle:'资金总账',
    titleField : 'SuoShuQi',
    templateCols:[ {
        name: 'space',
        text: '',
        xtype: 'template',
        width: 5,
        hideable: false,
        sortable: false
    }],
    /*
     * */
    constructor: function (config) {
        config = config || {};
        Rsd.apply(this, config);
    },
    reportHs:function reportHs()
    {
        Rsd.create('Rsd.Faith.admin.SysBuildDialog',{title:'资金总账核算',group:'ZZHS'}).showDialog();
    },
    suo_shu_qi_format:function (row) {
        var  btn = document.createElement('a');
        btn.href='#';
        btn.style.float='right';
        btn.innerHTML = '查看详情';
        $(btn).click (function(){
            Rsd.create('Rsd.Faith.dialogs.ReportZiJinZongZhangDialog',{data:row}).showDialog();
        } );

        return [btn];
    },
    zhuang_tai_format:function zhuang_tai_format(row) {
        var me = this;
        if(row['ZhuangTai'] == 'JZZ')
        {
            var _fn = null;
            if(false)
            {
                _fn =function () {
                    Rsd.alert('扎帐任务已提交');
                };
            }
            var _btn = Rsd.button('核算扎帐(未到期)',_fn,null,null,{backgroundColor:_fn==null?'grey':'green',borderColor: 'black',float:'right'});
            _btn.title = "核算本期账务数据,并扎帐";
            return [
                Rsd.newLine(),
                _btn];
        }
        if(row['ZhuangTai'] == "None")
        {
            return [
                Rsd.newLine(),
                Rsd.button('开始记账',function () {
                    Rsd.app.requestService('report.SetPeriodStart',{suoShuQi:row['SuoShuQi']},function (data) {
                        if(data.success)
                        {
                             me.load();
                        }
                        else {
                            Rsd.alert(data.msg);
                        }

                    });
                },null,null,{backgroundColor:'blue',borderColor: 'blue',float:'right'})];
        }
    }
});
